package com.example.tyz1201.bulls;

import android.media.Image;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Random;

public class MainActivity extends AppCompatActivity {
    TextView tv_question;
    TextView tv_times;
    TextView tv_points;
    SeekBar seek_bar;
    Button btn_over;
    ImageView iv_clear;
    ImageView iv_introduction;

    int i = 1, ran, pro, ps, points, sum = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tv_question = (TextView) findViewById(R.id.tv_question);
        tv_times = (TextView) findViewById(R.id.tv_times);
        tv_points = (TextView) findViewById(R.id.tv_points);
        seek_bar = (SeekBar) findViewById(R.id.seek_bar);
        btn_over = (Button) findViewById(R.id.bt_over);
        iv_clear = (ImageView) findViewById(R.id.iv_clear);
        iv_introduction = (ImageView) findViewById(R.id.iv_introduction);
        ran = getRandom();
        tv_times.setText("局数:" + 1);
        tv_points.setText("分数:" + 0);
    }

    int getRandom() {
        Random random = new Random();
        int count = random.nextInt(101);
        tv_question.setText("小样，把它拉到：" + count);
        return count;
    }

    void sumPoints() {
        pro = seek_bar.getProgress();
        ps = ran - pro;
        Math.abs(ps);
        points = 100 - ps;
        sum = sum + points;
        tv_points.setText("分数:" + sum);
        ran = getRandom();
    }

    void clear() {
        tv_question.setText("小样，把它拉到：" + ran);
        tv_points.setText("分数：" + 0);
        tv_times.setText("局数：" + 1);
        i = 1;
        sum = 0;
        seek_bar.setProgress(0);
    }

    public void button_listener1(View v) {
        Toast.makeText(MainActivity.this, "" + seek_bar.getProgress(), Toast.LENGTH_LONG).show();
        tv_times.setText("局数:" + (++i));
        sumPoints();
    }

    public void button_listener2(View v) {
        Toast.makeText(MainActivity.this, "All clear", Toast.LENGTH_LONG).show();
        clear();
    }

    public void button_listener3(View v) {
        Toast.makeText(MainActivity.this, "说明：玩家所拉进度条位置与给出位置越近，分数越高！", Toast.LENGTH_LONG).show();
    }
}
